package com.financing.controller.invest;
import java.util.Map;

import com.financing.model.Data;
import com.financing.model.invest.InvestLog;
import com.financing.model.user.User;
import com.financing.service.invest.InvestLogService;
import com.financing.util.Json;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

/**
 * 交易控制器
 */
public class InvestLogController extends Controller {
	private InvestLogService investLog = new InvestLogService();

	/**
	 * 获取我的交易记录
	 */
	public void info() {
		InvestLog log = InvestLog.me.findById(getParaToInt("id",1));
		renderJson(Json.ok("数据获取成功！", Data.put("item", log)));
	} 
	
	/**
	 * 获取我的交易记录
	 */
	public void myList() {
		User u = getAttr("user");
		int page = getParaToInt("page",1);
		int size = getParaToInt("size",10);
		Map<String, String> params =Data.flat(getParaMap());
		params.put("userId", String.valueOf(u.getId()));
		Page<InvestLog> list = investLog.list(page, size, params);
		renderJson(Json.ok("数据获取成功！", Data.put("page", list)));
	} 
	
	/**
	 * 交易记录列表
	 */
	public void list() { 
		int page = getParaToInt("page",1);
		int size = getParaToInt("size",10);
		Page<InvestLog> p = investLog.list(page,size,Data.flat(getParaMap()));
		p.getList().forEach(n->{
			n.put("user", User.me.findById(n.getUserId()));
		});
		renderJson(Json.ok( "数据获取成功！", Data.put("page", p)));
	}
}
 